
const getDefaultState = () => {
  return {
    myRate: 1, // 后台定义的折扣
    discountRate: 1,
    currentFilmId: 0, // 当前要购买的影片id
  }
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  },
  SET_DISCOUNT_RATE: (state, discountRate) => {
    state.discountRate = discountRate || 1
  },
  SET_CUR_FILM_ID: (state, filmId) => {
    state.currentFilmId = filmId || 0
  }
}

const actions = {
  reset({ commit }) {
    return new Promise(resolve => {
      commit('RESET_STATE')
      resolve()
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

